package com.ruipengkj.view.statementView;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;

import com.ruipengkj.view.base.BasePanel;
//集成分页组件
public class StatementDemo extends BasePanel {
		private static final long serialVersionUID = 1L;
		public static final DefaultTableCellRenderer DEFAULT_RENDERER =new DefaultTableCellRenderer();
		private JTable table;
		private JScrollPane tableJsp;
		private String[] colname = {"第1列","第2列","第3列"}; //表头信息
		public StatementDemo() {
			this.setLayout(new BorderLayout());
			this.init();
			this.makeFace();
		}
		private void init() {
			table=new JTable(3,3);
			//table设置列宽度 AUTO_RESIZE_SUBSEQUENT_COLUMNS 填满父容器  JTable.AUTO_RESIZE_OFF 自适应
			table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
			tableJsp=new JScrollPane(table);
			int vCollIndex=0;
			
			
			//this.getTableCellRendererComponent(table, null, false, false, 1, 2);
			this.add(tableJsp, BorderLayout.CENTER);
		}
		 private void makeFace() {
	         //新建列表现器------------------------//
	         DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
	             public Component getTableCellRendererComponent(JTable table, Object value,
	                     boolean isSelected, boolean hasFocus, int row, int column) {
	                 Component cell = super.getTableCellRendererComponent  
	                         (table, value, isSelected, hasFocus, row, column);
	                 if(row==0 && column==0 && cell.isBackgroundSet())//设置变色的单元格
	                     cell.setBackground(Color.red);
	                 else if(row==2 && column==2 && cell.isBackgroundSet())//设置变色的单元格
	                     cell.setBackground(Color.red);
	                 else
	                     cell.setBackground(Color.WHITE);
	 
	                 return cell;
	             }
	         };
//	         //设置列表现器------------------------//
//	         for(int i = 0; i < 3; i++) {
//	             table.getColumn(i).setCellRenderer(tcr);
//	         }
	         TableColumnModel tcm = table.getColumnModel();
	         for(int i = 0; i < tcm.getColumnCount(); i++) {
	             tcm.getColumn(i).setCellRenderer(tcr);
	         }	         
	                 
	         tableJsp.getViewport().setBackground(Color.WHITE);
	         tableJsp.getViewport().add(table);
	         
	         //总体界面布局------------------------//
	         
	         this.add(tableJsp, BorderLayout.CENTER);
	     }
		@Override
		public void clear() {
			// TODO Auto-generated method stub
			
		}
}
